package com.gs.xbinfomytest.controller;

import com.gs.xbinfomytest.log.LogRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: srpingbootdatajpa
 * @Package: com.gs.controller
 * @Description: java类作用描述
 * @Author: Administrator
 * @CreateDate: 2018/10/8 15:22
 * @UpdateUser: Administrator
 * @UpdateDate: 2018/10/8 15:22
 * @UpdateRemark: The modified content
 * @Version: 1.0
 **/
@Controller
public class ErrorMainController implements ErrorController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping("/error")
    @LogRecord(value = "页面请求错误")
    public String handleError(HttpServletRequest request) {
        //获取statusCode:401,404,500
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        logger.info("获取到的statusCode是：{}", statusCode);
        /*if(statusCode == 401){
            return "/401";
        }else if(statusCode == 404){
            return "error404";
        }else if(statusCode == 403){
            return "/403";
        }else{
            return "/500";
        }*/
        return "error404";
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }


}
